# from django.http import JsonResponse
#
#
# def func_out(func):
#     def func_in(request, *args, **kwargs):
#         if request.user.is_authenticated:
#             return func(request, *args, **kwargs)
#         else:
#             return JsonResponse({'code': 400,
#                                  'errmsg': '请先登录'})
#
#     return func_in
#
#
# class LoginRequiredMixin(object):
#     '''自定义的Mixin扩展类'''
#
#     @classmethod
#     def as_view(cls, **initkwargs):
#         view = super().as_view(**initkwargs)
#         return func_out(view)
from django.http import JsonResponse


def func_out(func):
    def func_in(request, *args, **kwargs):
        if request.user.is_authenticated:

            return func(request, *args, **kwargs)
        else:
            return JsonResponse({'code': 400,
                                 'errmsg': '请登录账户'})

    return func_in


class LoginRequiredMixin(object):
    @classmethod
    def as_view(cls, **initkwargs):
        view = super().as_view(**initkwargs)
        return func_out(view)
